<!--
 * @Author: tansq
 * @Date: 2021-09-17 15:20:31
 * @LastEditTime: 2022-12-01 16:21:49
 * @LastEditors: tansq
 * @Description: 
 * @FilePath: \hte-vue-dev\src\views\library\company\components\ImportAreaData.vue
 * 可以输入预定的版权声明、个性签名、空行等
-->

<template>
  
      
      <div class="content">
        <!-- <a-form-model
          class="hte-form-model"
          ref="ruleForm"
          :model="form"
          :rules="rules"
        >
           <section>
            <div class="section-header">
              公司库初始化数据
             
            </div>
             <div class="hte-btn-group" style="16px 0"> 
                <a-button class="hte-btn add-btn" type="primary" @click="importExcelDataBtn">导入</a-button>
                <a-button class="hte-btn add-btn" @click="handleDelete">删除</a-button>
             
            </div>
         
            <div class="section-table">
              <a-table
                :scroll="{ x: '100%' }"
                class="hte-table-content"
                :columns="payColumns"
                :data-source="sourceData"
                :pagination="pagination"
                rowKey="rowKey"
                :row-selection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
                :loading="tabLoading"
                bordered
                size="middle"
                @change="pageChange"
              >
                <template slot="num" slot-scope="text, record, index">
                  {{ (currPageIndex - 1) * currPageSize + parseInt(index) + 1 }}
                </template>
                <template slot="teamName" slot-scope="text, record">
                  <a-input v-model="record.teamName" />
                </template>
                <template slot="completedTotal" slot-scope="text, record">
                  <a-input v-model="record.completedTotal" />
                </template>
                <template slot="operation" slot-scope="text, record">
                  <a @click="handleDelete(record, 'sourceData')">删除</a>
                </template>
              </a-table>
            </div>
          </section>
        
        </a-form-model>         -->
        <excel-paste   :columnsExcel="payColumns" :exportXlsTemplateUrl="importExcle.exportXlsTemplateUrl" :showBtu="false"  :excelVisible="importExcle.excelVisible" :excelConfirmLoading="importExcle.excelConfirmLoading"   @handleOkExcel="handleOkExcel" @handleCancelExcel="handleCancelExcel"></excel-paste>
      </div>      
    
</template>
<script>
import '@/config/upload.install.js'
import LibFileAttach from '@/views/library/batchFile/LibFileAttach';
import { companyMixin,companyValidate } from '@/views/library/company/companyMixin'
import {randomUUID} from '@/utils/util'
import { isDateYYYYMMDD,isNumber,isArea } from '@/utils/validate'
import { deleteAction, getAction,postAction,downFile,getFileAccessHttpUrl } from '@/api/manage'
export default {
  name:'ImportAreaData',
  components: {
    ExcelPaste:()=>import('@/components/excelPaste/ExcelPaste'),
  },
  mixins: [],
  props: {
    dics:{
      type:Object,
      default:()=>{return {}}
    }
  },
  data() {
    return {

      labelCol: { span: 8 },
      wrapperCol: { span: 15 },
      form: {
      },
      pagination: {
        total: 0,
        current: 1,
        pageSize:100
      },
      tabLoading: false,
      currPageIndex: 1,
      currPageSize: 10,
      payColumns: [
        {
          title: '序号',
          dataIndex: 'rowIndex',
          width: '50px',
          align: 'center',
          fixed: 'left',
            customRender:function (t,r,index) {
                return parseInt(index)+1;
            },
            isImportExcelColumns:false
        },
        {
          title: '公司名称',
          // fixed: 'left',
          dataIndex: 'companyName',
          width: '180px',
          align: 'center',
        },
     
         {
          title: '国家',
          dataIndex: 'country',
          align: 'center',
          width: '150px',
        },
        {
          title: '省级行政区',
          dataIndex: 'provincialNationalStandard',
          align: 'center',
          width: '120px',
        },
        {
          title: '市级行政区',
          dataIndex: 'cityStandard',
          align: 'center',
          width: '120px',
        },
         {
          title: '县级行政区',
          dataIndex: 'countyStandard',
          align: 'center',
          width: '150px',
        },
          {
          title: '详情地址',
          dataIndex: 'addressDetails',
          align: 'center',
          width: '150px',
          ellipsis: true,
        },
        
      ],
      sourceData: [
       
      ],
      importExcle:{
        excelVisible:false,
        excelConfirmLoading:false,
        exportXlsTemplateUrl:'templates/excel/公司库基础信息模板.xlsx'
      },
      visibleModel: false,
     
      selectedRowKeys:[],
       url:{
        'addBatch':'/libraryCompany/hteLibCompany/areaInit'
      },
    }
  },
  created() {

  },
  mounted() {},
  methods: {
    pageChange(page) {
      this.currPageIndex = page.current
      this.currPageSize = page.pageSize
      this.pagination.current = page.current
      
    },
    onSelectChange(selectedRowKeys) {
      this.selectedRowKeys = selectedRowKeys
    },
  
    handleClassOk() {
      this.visibleModel = false
    },
    handlePersonnel(type, item) {
      if (type === 'edit') {
        Object.assign(this.visibleForm, item)
      }
      this.visibleModel = true
    },
 
  
     handleOkExcel:function(data = []){
        let that = this;

         this.importExcle.excelConfirmLoading = true;
         if(data.length==0){
           this.$message.warning(`操作异常:请导入数据`);
                 this.importExcle.excelConfirmLoading = false;
                return false;
         }
       

        postAction(this.url.addBatch,data).then(res=>{
          if(res.code == 200){
            this.$message.success('导入成功');    
            this.handleCancelExcel();
          }else{
            this.$message.error(res.message);
          }
        }).finally(res=>{
           this.importExcle.excelConfirmLoading = false;

        })
        
        that.sourceData.push(...data)
       
        
       
       
      },
     
      importExcelDataBtn:function(){
         this.importExcle.excelConfirmLoading = false;
         this.importExcle.excelVisible = true;
      },
      handleCancelExcel:function(){
        this.$emit("ok")
        this.importExcle.excelVisible = false;
      },
  },

}
</script>
<style lang="less" scoped>
@import '~@assets/less/hte-main.less';
@import '~@views/library/company/company.less';
</style>
